package com.traffic.between.adaptor;

import java.util.Date;
import org.apache.log4j.Logger;
import com.traffic.between.annotation.ChooseProvider;
import com.traffic.between.config.BetweenProperties;
import com.traffic.between.config.OrderInfoContext;
import com.traffic.between.redis.running.BsmOrderResultExecutor;
import com.traffic.between.service.LingDianServiceImpl;
import com.traffic.managent.service.order.bean.OrderBean;

import net.sf.json.JSONObject;

@ChooseProvider(channel = "lingdian")
public class LingDianAdaptor implements IAdaptor{

	private static Logger log = Logger.getLogger(LingDianAdaptor.class);
	
	
	public void order() {
		OrderBean orderBean = OrderInfoContext.getContext();
		orderBean.setSendTime(new Date());
		
		String spec = orderBean.getProductCode();
		String mobiles = orderBean.getPhoneNo();
		String tradeNo = orderBean.getIds();
		String url = BetweenProperties.CALLBACK_URL+"Lingdian";
		String region = orderBean.getRegion();
		log.info("between- 零点 LingDianService.order() 订购请求参数:spec" + spec+",mobiles:"+mobiles+",tradeNo:"+tradeNo+",url:"+url+",region:"+region);
		String result = LingDianServiceImpl.service.order(spec,mobiles,tradeNo,url,region);

		JSONObject json = JSONObject.fromObject(result);

		int code = json.getInt("code");

		if ("0".equals(String.valueOf(code))) {
			orderBean.setStatus("10");
			orderBean.setMessage("下单成功");
			orderBean.setErrorMsg("下单成功");
		} else {
			orderBean.setStatus("8");
			orderBean.setMessage(json.getString("message"));
			orderBean.setErrorMsg(json.getString("message"));
		}
		
		BsmOrderResultExecutor.service.setOrder(orderBean);
	}

	
	
}
